package com.artlongs.base.vo;

import java.util.Collection;

/**
 * <p>Function:业务层统一的返回值包装VO</p>
 *
 * @version $Revision$ $Date$
 *          Date: 15-5-28
 *          Time: 下午12:25
 * @author: lqf
 * @since 1.0
 */
public class BizRetVo<T> {

    private BizRetCode retCode = BizRetCode.NOT_ERROR;
    private String ref= "";  //页面跳转地址
    private String msg= "";  //返回提示信息
    private T item;//返回单个对象
    private Collection<T> items;//返回对象列表

    public BizRetVo() {
    }

    public BizRetVo(BizRetCode retCode) {
        this(retCode, null, "", null);
    }

    public BizRetVo(BizRetCode retCode, T item) {
        this(retCode, null,"", item, null);
    }

    public BizRetVo(BizRetCode retCode, Collection<T> items) {
        this(retCode, null, "",null, items);
    }

    public BizRetVo(BizRetCode retCode, String msg) {
        this(retCode, msg, "", null,null);
    }

    public BizRetVo(BizRetCode retCode,String msg, String ref) {
        this(retCode, msg, ref,null,null);
    }

    public BizRetVo(BizRetCode retCode,String msg, String ref,T item) {
        this(retCode, msg, ref, item,null);
    }

    public BizRetVo(BizRetCode retCode,String msg, String ref, T item, Collection<T> items) {
        this.retCode = retCode;
        this.ref = ref;
        this.item = item;
        this.items = items;
        if (msg != null && msg.trim().length() > 0) {
            this.setMsg(msg);
        }
    }
    public void setError(String msg) {
        retCode = BizRetCode.FAIL;
        setMsg(msg);
    }

    public void setSuccess(String msg) {
        retCode = BizRetCode.SUCCESS;
        setMsg(msg);
    }

    public String getMsg() {
        return (this.msg==null || msg.trim().length() == 0)?retCode.getMsg():this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 判断返回的消息是否成功
     * @return
     */
    public boolean isSucc(){
        return BizRetCode.SUCCESS == retCode;
    }

    public BizRetCode getRetCode() {
        return retCode;
    }

    public String getRetCodeVal() {
        return retCode.getRetCode();
    }

    public void setRetCode(BizRetCode retCode) {
        this.retCode = retCode;
    }

    public T getItem() {
        return item;
    }

    public void setItem(T item) {
        this.item = item;
    }

    public Collection<T> getItems() {
        return items;
    }

    public void setItems(Collection<T> items) {
        this.items = items;
    }

    public String getRef() {
        return ref;
    }

    public void setRef(String ref) {
        this.ref = ref;
    }



}
